home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12894 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: nntp.teleport.com!usenet
  2. From: GHouck <hksys@teleport.com>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Opening STDOUT As BINARY
  5. Date: 3 Apr 1996 12:49:22 GMT
  6. Organization: systems hk
  7. Message-ID: <4jts4i$h8d@nadine.teleport.com>
  8. References: <3161CAD8.296C@netrover.com>
  9. NNTP-Posting-Host: ip-pdx01-07.teleport.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.22 (Windows; I; 32bit)
  14.  
  15. Stephane Charette <charrick@netrover.com> wrote:
  16. >I've come across a problem, and I believe that it is
  17. >caused by limitations in C/C++.  Can anyone help on the
  18. >following:
  19. >
  20. >I need to output binary information to the console, which
  21. >is then redirected to a file by the o/s.  At the moment,
  22. >I'm using printf( "%c", mychar ) to output the the binary
  23. >data one character at a time as it comes in.
  24. >
  25. >However, it seems that the character #7 (0x07, bell) gets
  26. >sent to stdout followed by an automatic CR (0x0A).  Every
  27. >other character in the ASCII table works fine!  Is there
  28. >a way to reopen stdout in binary mode instead of as a text
  29. >stream? The extra 0x0A characters are corrupting the data!
  30. >
  31. >I've also tried "cout" and "putc", but they yield the same
  32. >result.
  33. >
  34. >Why do I need this:  this application runs as a CGI-BIN,
  35. >and the web server EXPECTS the output to be sent to
  36. >stdout.  I cannot fwrite() this information to a physical
  37. >file since the web server is capturing the console output!
  38. >
  39. Stephane,
  40.  
  41. I know I'll catch hell for this in this group, but the following
  42. worked for me (using Borland 4.5 on Windows NT). I don't
  43. know if setmode is a portable/standard function, but perhaps
  44. something similar exists for you:
  45.  
  46.   if( fInp == stdin )       /* set std-input to binary */
  47.     setmode( 0,O_BINARY );
  48.  
  49.   if( fOut == stdout )     /* set std-output to binary */
  50.     setmode( 1,O_BINARY );
  51.  
  52. Yours, Geoff Houck
  53.  
  54.